import {api} from './libs/api.js';
let _self;
export const index =  {
	data() {
		return {
			optLock:false,
			formData:{
				waizhijing:0,
				waibanjing:0,
				neizhijing:0,
				neibanjing:0,
				houdu:0,
				changdu:0,
				kuandu:0,
				mianji:0,
				danjia:0,
				zongjia:0,
			},
			rules:api.rules
		}
	},
	
	mounted() {
		_self = this;
	},
	onReachBottom:function(e){
		/*this.params.page+=1;
		this.initData();*/
	},
	onLoad:function(option) {
		//this.tabSubItem=option.status;
	},
	
	methods: {
		async initData(){
			
		},
		
		inputWaizhijing(){
			this.formData.waibanjing=this.formData.waizhijing/2==0 ? '' : this.formData.waizhijing/2;
			this.getChangdu();
		},
		
		inputWaibanjing(){
			this.formData.waizhijing=this.formData.waibanjing*2==0 ? '' : this.formData.waibanjing*2;
			this.getChangdu();
		},
		

		inputNeizhijing(){			
			this.formData.neibanjing=this.formData.neizhijing/2==0 ? '' : this.formData.neizhijing/2;
			this.getChangdu();
		},
		
		
		inputNeibanjing(){
			this.formData.neizhijing = this.formData.neibanjing*2==0 ? '' : this.formData.neibanjing*2;
			this.getChangdu();
		},
		
		//输入厚度
		inputHoudu(){
			this.getChangdu();
		},
		
		
		//计算长度
		getChangdu(){
			var houdu = this.formData.houdu;
			var waibanjing = this.formData.waibanjing;
			var neibanjing = this.formData.neibanjing;
			
			var acc1 = this.accMul(waibanjing,waibanjing) - this.accMul(neibanjing,neibanjing);
			
			var acc2 = this.accMul(3.14159265358979, acc1);
			
			var acc3 = this.accDiv(acc2, houdu);
			
			var changdu = this.accDiv(acc3, 10);
			this.formData.changdu=changdu;
			this.getMianji();
		},
		
		
		
		
		 //输入长度
		inputChangdu(){
			this.getHoudu();
		},
		//计算厚度
		getHoudu(){
			var changdu = this.formData.changdu;
			var waibanjing = this.formData.waibanjing;
			var neibanjing = this.formData.neibanjing;
			var acc1 = this.accMul(waibanjing,waibanjing) - this.accMul(neibanjing,neibanjing);
			var acc2 = this.accMul(3.14159265358979, acc1);
			var acc3 = this.accDiv(acc2, 10);
			var houdu = this.accDiv(acc3, changdu);
			this.formData.houdu=houdu;
			this.getMianji();
		},
		    
			
			
			
			
		//输入宽度
		inputKuandu(){
			this.getMianji();
		},
		
		            //计算面积
		getMianji(){
			var changdu = this.formData.changdu;
			var kuandu  = this.formData.kuandu;
			var mianji  = this.accMul( this.accDiv(kuandu,100), changdu );
			this.formData.mianji=mianji;
			this.getZongjia();
		},
		    
		//输入单价
		inputDanjia(){
			this.getZongjia();
		},
		//计算总价
		getZongjia(){
			var danjia  = this.formData.danjia;
			var mianji  = this.formData.mianji;
			var zongjia = this.toFixed( this.accMul(danjia, mianji), 8);
			this.formData.zongjia=zongjia?zongjia:0;
		},
		    
		//arg1除以arg2的精确结果 
		accDiv(arg1,arg2) { 
		 var t1=0,t2=0,r1,r2; 
			try{t1=arg1.toString().split(".")[1].length}catch(e){} 
			try{t2=arg2.toString().split(".")[1].length}catch(e){} 
			r1=Number(arg1.toString().replace(".",""))
			r2=Number(arg2.toString().replace(".","")) 
			return (r1/r2)*Math.pow(10,t2-t1); 
		},
		            //arg1乘以arg2的精确结果 
		accMul(arg1,arg2) { 
			var m=0,s1=arg1.toString(),s2=arg2.toString(); 
			
			
			try{m+=s1.split(".")[1].length}catch(e){} 
			try{m+=s2.split(".")[1].length}catch(e){} 
			return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m) 
		},
		            //保留几位小数
		toFixed(num1,num2){
			return parseFloat(num1).toFixed(num2);
		}

				
	},
}